package com.zzqstart.aclservice.security;

import com.zzqstart.commonutils.JwtUtils;
import io.jsonwebtoken.CompressionCodecs;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * <p>
 * token操作工具类
 * </p>
 */
@Component
public class TokenManager {

    private long tokenExpiration = 24 * 60 * 60 * 1000;
    private String tokenSignKey = "ukc8BDbRigUDaY6pZFfWus2jZWLPHO";

    public String createToken(String username) {
        String token = JwtUtils.getJwtToken("admin", username);
        return token;
    }

    public String getUserFromToken(String token) {
        String user = (String) Jwts.parser().setSigningKey(tokenSignKey).parseClaimsJws(token).getBody().get("nickname");
        return user;
    }

    public void removeToken(String token) {
        //jwttoken无需删除，客户端扔掉即可。
    }

}
